﻿using System;
using UnityEngine.SceneManagement;

namespace Framework.Resource
{

    public delegate void InitResourceCallback(bool result);
    public delegate void UpdateResourceVersionCallback(bool result,bool needDown);
    // public delegate void LoadAssetCallback(LoadAssetSuccessCallback successCallback,LoadAssetFailureCallback failureCallback);

    public delegate void LoadAssetSuccessCallback(string assetName,Object asset,object userData);
    public delegate void LoadAssetFailureCallback(string assetName,string errorInfo,object userData);
    public delegate void LoadSceneCallback(string sceneAssetName,bool result);

    public delegate void UnloadAssetCallback(string assetName,bool result);
    public delegate void UnloadSceneCallback(string sceneAssetName,bool result);
    public delegate void UnLoadUnusedAssetsCallback(bool result);
    public class LoadAssetCallback
    {
        private LoadAssetSuccessCallback m_successCallback;
        public LoadAssetSuccessCallback LoadAssetSuccessCallback => m_successCallback;
        private LoadAssetFailureCallback m_failureCallback;
        public LoadAssetFailureCallback LoadAssetFailureCallback => m_failureCallback;

        public LoadAssetCallback(LoadAssetSuccessCallback successCallback,LoadAssetFailureCallback failureCallback=null)
        {
            m_successCallback = successCallback;
            m_failureCallback = failureCallback;
        }
    }

    public class DownloadCallback
    {
         public delegate void OnDownloadOver(bool isSucceed);
         public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
         public delegate void OnDownloadError(string fileName, string error);
         public delegate void OnStartDownloadFile(string fileName, long sizeBytes);

         public OnDownloadOver OnDownloadOverFunction;
         public OnDownloadProgress OnDownloadProgressUpdateFunction;
         public OnDownloadError OnDownloadErrorFunction;
         public OnStartDownloadFile OnStartDownloadFileFunction;

    }
    
    public interface IResourceManager
    {
        public void InitResource(InitResourceCallback callback);
        public void UpdateResourceVersion(UpdateResourceVersionCallback versionCallback);
        public void LoadAsset<T>(string assetName,LoadAssetCallback callback, object userData) where T : UnityEngine.Object;
        public void LoadAsset(string assetName, Type assetType,LoadAssetCallback callback,object userData);
        public void UnloadAsset(string assetName,UnloadAssetCallback callback);
        public void UnloadAsset(Object asset,UnloadAssetCallback callback);
        public void LoadScene(string sceneName,LoadSceneCallback callback, LoadSceneMode mode , bool suspendLoad );
        public void UnLoadScene(string sceneName,UnloadSceneCallback callback);
        public void UnLoadUnusedAssets(UnLoadUnusedAssetsCallback callback);
        public T LoadAssetSync<T>(string assetName) where T : UnityEngine.Object;
        public Object LoadAssetSync(string assetName,Type assetType);

        public void DownRemoteResource(DownloadCallback downloadCallback);
    }

}